//
//  TopUpPromptView.m
//  TenMinDemo
//
//  Created by Shawn Li on 2021/3/8.
//  Copyright © 2021 CYXiang. All rights reserved.
//

#import "TopUpPromptView.h"
@interface TopUpPromptView()
@property (weak, nonatomic) IBOutlet NSLayoutConstraint *bgBottom;
@property (weak, nonatomic) IBOutlet UIView *bgView;
@end
@implementation TopUpPromptView
INITFROMXIB

- (void)awakeFromNib{
    [super awakeFromNib];
    CGRect frame = self.bgView.bounds;
    frame.size.width = SCREEN_WIDTH;
    UIBezierPath *maskPath = [UIBezierPath bezierPathWithRoundedRect: frame byRoundingCorners:UIRectCornerTopLeft | UIRectCornerTopRight cornerRadii:CGSizeMake(10,10)];
      //创建 layer
      CAShapeLayer *maskLayer = [[CAShapeLayer alloc] init];
      maskLayer.frame = frame;
      //赋值
      maskLayer.path = maskPath.CGPath;
    self.bgView.layer.mask = maskLayer;
}

- (void)showInView:(UIView *)view{
    [view addSubview:self];
    [self show];
}


- (void)show{
    self.backgroundColor = [UIColor clearColor];
    self.bgBottom.constant = -480;
    [UIView animateWithDuration:0.35 animations:^{
        self.backgroundColor = [[UIColor alloc] initWithWhite:0 alpha:0.8];
        self.bgBottom.constant = 0;
        [self layoutIfNeeded];
        } completion:^(BOOL finished) {
            
        }];
    
}

- (void)hide{
    [self endEditing:YES];
    [UIView animateWithDuration:0.35 animations:^{
       
        self.backgroundColor = [UIColor clearColor];
        self.bgBottom.constant = -480;
        [self layoutIfNeeded];
        } completion:^(BOOL finished) {
            [self removeFromSuperview];
        }];
    
}
- (IBAction)doneAction:(id)sender {
    [self hide];
}

@end
